package com.learn.countdown;

import com.learn.semaphore.TestSemaphore;
import org.apache.log4j.Logger;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

/**
 * @author ln
 * @Description: ${todo}
 * @date 2020/12/30
 */
public class TestCountDownLatch {
    final static Logger log=Logger.getLogger(TestCountDownLatch.class);


    public static void main(String[] args) throws Exception {
        CountDownLatch countDownLatch = new CountDownLatch(3);

        new Thread(()->{
            try {
                log.debug("begin....");
                TimeUnit.SECONDS.sleep(1);
                countDownLatch.countDown();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        new Thread(()->{
            try {
                log.debug("begin....");
                TimeUnit.SECONDS.sleep(2);
                countDownLatch.countDown();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        new Thread(()->{
            try {
                log.debug("begin....");
                TimeUnit.SECONDS.sleep(1);
                countDownLatch.countDown();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }).start();

        log.info("waiting....");
        countDownLatch.await();
        log.info("wait end....");
    }
}
